package team.seekers.skill.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.BeanUtils;
import team.seekers.skill.entity.dao.SectionBlog;
import team.seekers.skill.entity.dao.SectionVideo;
import team.seekers.skill.entity.vo.admin.update.AdminBlogUpdateVO;
import team.seekers.skill.entity.vo.admin.update.AdminSectionUpdateVO;
import team.seekers.skill.entity.vo.admin.update.AdminVideoUpdateVO;
import team.seekers.skill.mapper.SectionVideoMapper;
import team.seekers.skill.service.SectionVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 这一节的视频链接 服务实现类
 * </p>
 *
 * @author hbc
 * @since 2021-02-28
 */
@Service
public class SectionVideoServiceImpl extends ServiceImpl<SectionVideoMapper, SectionVideo> implements SectionVideoService {

    @Override
    public boolean removeBySectionId(String sectionId) {
        QueryWrapper<SectionVideo> wrapper = new QueryWrapper<>();
        wrapper.eq("section_id",sectionId);
        boolean remove = remove(wrapper);
        return remove;
    }

    @Override
    public List<AdminVideoUpdateVO> listAdminVideoUpdateVOBySectionId(String sectionId) {
        QueryWrapper<SectionVideo> wrapper = new QueryWrapper<>();
        wrapper.eq("section_id",sectionId);
        wrapper.orderByAsc("sequence");
        List<SectionVideo> list = list(wrapper);
        if(list == null){
            return null;
        }
        List<AdminVideoUpdateVO> adminVideoUpdateVOList = new ArrayList<>();
        for (SectionVideo sectionVideo : list) {
            AdminVideoUpdateVO adminVideoUpdateVO = new AdminVideoUpdateVO();
            BeanUtils.copyProperties(sectionVideo,adminVideoUpdateVO);
            adminVideoUpdateVOList.add(adminVideoUpdateVO);
        }
        return adminVideoUpdateVOList;
    }
}
